/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_Form.h"
using namespace prs;

// TNodeForm //////////////////////////////////////////////////////////////////

//
TNodeUseTemplate *TNodeForm::SearchUseTemplateByDefTemplateId(
  const svl::TString &DefTemplateId
)
{
  TNode *P = TNodeSearch(this)
   .GotoChildren()
    .SearchByAttrNameAndValue(attrName_NodeDefTemplateId,DefTemplateId)
    .SearchByType(nodeType_UseTemplate)
    //.SearchByType(TNodeFrmUseTemplateParamControls::nodeType,true)
     //.SearchById(Id)
      .GetFirst()
  ;

  return dynamic_cast<TNodeUseTemplate*>(P);
}

// TRuleForm //////////////////////////////////////////////////////////////////

//
TRuleForm::TRuleForm(
  snt::text::TContext &Context,
  svl::TVariant &VParentNode,
  TRuleSetNodeIdNecessarily &RSetNodeIdNecessarily,
  TRuleSetNodeIdOptionally  &RSetNodeIdOptionally,
  TRuleFrmGeom &RFrmGeom,
  TRuleSetAttrValue &RSetAttrValue,
  TRuleFrmValue &RFrmValue,
  TRuleSetStyle &RStyle,
  TRuleFrmChildren &RChildren
)
:vParentNode(VParentNode)
,RUseTemplate(Context,vParentNode,RChildren,RFrmValue)
{
  RChildren.Init(RUseTemplate);
  
  TFuncNewNodeIntoAttrOldChildren FNewNode;
  snt::TReturn Return;
  snt::text::TKeyword K(Context);

  vThis = this;

  this->Name(GetClassName()).Local(vParentNode)
  | K.New("form") & FNewNode.New(vParentNode,TNodeForm()) 
    & RSetNodeIdNecessarily.New() 
    & RAttr.New() 
    & Return.New()
  ;
  
  RAttr.Name(GetClassName() + "[RAttr]")
  | AAttr.New()
  ;
  AAttr.Name(GetClassName() + "[AAttr]")
  | RStyle.New()    & AAttr.New()
  | RChildren.New() & Return.New()
  ;

  //svl::TMessageModal(GetClassName() << ":"
  //  << "\r\n" << GetGraphInfo(""));
}

//
TNodeForm &TRuleForm::GetNode()
{
  TNodeForm *Node = dynamic_cast<TNodeForm*>(vParentNode.Pointer()); 
  
  if (!Node) { 
    Except("GetNode[!Node]");
  }
  return *Node;
}
